<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 8/15/14
 * Time: 11:16 AM
 */

namespace Admin\Factory\Category;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\Hydrator;
use Admin\Mapper;

class AdminCategoryMapperFactory implements  FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $options = $serviceLocator->get('admin_module_options');

        /* @var $dbAdapter Db\Adapter\Adapter */
        $dbAdapter = $serviceLocator->get('user_zend_db_adapter');

        $mapper = new Mapper\Category\AdminCategory();
        $mapper->setDbAdapter($dbAdapter);

        $entityClass = $options->getCategoryEntityClass();

        /* @var $hydrator Hydrator\HydratorInterface */
        $hydrator = $serviceLocator->get('category_hydrator');

        $mapper
            ->setEntityPrototype(new $entityClass)
            ->setHydrator($hydrator)
            ->setTableName($options->getCategoryTableName())
        ;

        return $mapper;

    }
} 